package com.schoolcloud.serve.controller;

import com.schoolcloud.common.model.PageDTO;
import com.schoolcloud.common.model.R;
import com.schoolcloud.serve.entity.Spu;
import com.schoolcloud.serve.query.SpuQuery;
import com.schoolcloud.serve.service.SpuService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/serve/re-market/spu")
@RequiredArgsConstructor
public class SpuController {
    private final SpuService spuService;

    @GetMapping("/page")
    public R<PageDTO<Spu>> getSpuPage(SpuQuery query) {
        PageDTO<Spu> page = spuService.getSpuPage(query);
        return R.ok(page);
    }
    @PutMapping
    public R<Void> modifySpu(@RequestBody Spu spu) {
        spuService.updateById(spu);
        return R.ok();
    }
    @DeleteMapping("/{id}")
    public R<Void> removeSpu(@PathVariable Integer id) {
        spuService.removeById(id);
        return R.ok();
    }
    @GetMapping("/{id}")
    public R<Spu> getSpu(@PathVariable Integer id) {
        Spu spu = spuService.getById(id);
        return R.ok(spu);
    }
}
